
float xpos=200, ypos=200;    // Starting position of head
float 	[] snake = new float[20]; 
int x_direction_head = 1 ;//
int y_direction_head = 0 ;//
int dir=1;
int x,y;

float xspeed = 5.5;  //
float yspeed = 5.5;  // 
float xpos_tail, ypos_tail;


void setup() 
{
  size(600, 400);
 
  background(221);
  
}

void draw() 
{
    background(221);
  
xpos = (xpos + ( xspeed * x_direction_head ));
ypos = (ypos + ( yspeed * y_direction_head ));
rect(xpos,ypos,20,20);
  xpos_tail = xpos-22*x_direction_head;
  ypos_tail = ypos-22*y_direction_head;
  rect(xpos_tail,ypos_tail,20,20);
  
   
  

    
   
   
  
}


void keyPressed() {
  if (key == CODED) {
    if (keyCode == LEFT) {
       if(dir==1)
       {
         dir=4;
         x_direction_head=0;
         y_direction_head=-1;
       } else{
       if(dir==2)
       {
          dir=1;
         x_direction_head=1;
         y_direction_head=0;
       } else{
         if(dir==3)
       {
          dir=2;
         x_direction_head=0;
         y_direction_head=1;
       } else{
        if(dir==4)
       {
          dir=3;
         x_direction_head=-1;
         y_direction_head=0;
       }}}}
    } else if (keyCode == RIGHT) {
   if(dir==1)
       {
         dir=2;
         x_direction_head=0;
         y_direction_head=1;
       } else{
       if(dir==2)
       {
          dir=3;
         x_direction_head=-1;
         y_direction_head=0;
       } else{
         if(dir==3)
       {
          dir=4;
         x_direction_head=0;
         y_direction_head=-1;
       } else{
        if(dir==4)
       {
          dir=1;
         x_direction_head=1;
         y_direction_head=0;
       }}}}
    } 
  } else {

  }
}
